#ifndef MATERIAL_H_
#define MATERIAL_H_

#include <GL/glew.h>
#include "SDL/SDL_image.h"

#include <fstream>


#include "factory.h"
#include "util.h"
#include "draw.h"

class CMaterialFrame : public CFactoryObject
{
	
private:
	
	GLuint m_Texture;
	
	int m_FramePause;
	int m_FrameWidth, m_FrameHeight;
	
	Vector2D m_Offset;
	
	std::string m_Tag;
	
public:

	inline void Bind()
	{
		
		Draw::BindTexture( m_Texture );
			
	}
	
	inline void CopyOver( CMaterialFrame * f )
	{
		
		f->m_Texture = m_Texture;
		f->m_Tag = m_Tag;
		f->m_FrameWidth = m_FrameWidth;
		f->m_FrameHeight = m_FrameHeight;
		
	}

	inline int GetWidth()
	{
		
		return m_FrameWidth;
		
	}
	
	inline int GetHeight()
	{
		
		return m_FrameHeight;
		
	}
	
	inline int GetPause()
	{
		
		return m_FramePause;
		
	}
	
	inline void SetPause( int p )
	{
		
		m_FramePause = p;
		
	}
	
	inline void SetFrameOffset( double x, double y )
	{
		
		m_Offset.x = x;
		m_Offset.y = y;
		
	}
	
	inline void SetTag( std::string s )
	{
		
		m_Tag = s;
		
	}
	
	inline std::string GetTag()
	{
		
		return m_Tag;
		
	}
	
	inline void SetSize( int w, int h )
	{
		
		m_FrameWidth = w;
		m_FrameHeight = h;
		
	}

	inline GLuint & GetTexture()
	{
	
		return m_Texture;

	}
	
	inline Vector2D & GetFrameOffset()
	{
	
		return m_Offset;
		
	}
	
	CMaterialFrame();
	~CMaterialFrame();
	
	void Load( std::string );
	
};

class CMaterial : public CFactoryObject
{

private:

	std::vector< CMaterialFrame * > m_pFrames;
	
	int m_RepeatFrame;

public:
	
	inline GLuint GetUint( int i )
	{
		
		return m_pFrames[i]->GetTexture();
		
	}
	
	inline void SetRepeatFrame( int i )
	{
		
		m_RepeatFrame = i;
		
	}
	
	inline int GetRepeatFrame()
	{
		
		return m_RepeatFrame;
		
	}

	inline std::string GetFrameTag( int i )
	{
		
		return m_pFrames[i]->GetTag();
		
	}

	inline void BindFrame( int i )
	{

		m_pFrames[i]->Bind();

	}
	
	inline Vector2D & GetFrameOffset( int i )
	{
	
		return m_pFrames[i]->GetFrameOffset();
		
	}
	
	inline int GetFrameCount()
	{
	
		return m_pFrames.size();
		
	}
	
	inline int GetFramePause( int i )
	{
	
		return m_pFrames[i]->GetPause();
		
	}
	
	inline int GetFrameWidth( int i )
	{
		
		return m_pFrames[i]->GetWidth();
		
	}
	
	inline int GetFrameHeight( int i )
	{
	
		return m_pFrames[i]->GetHeight();
		
	}
	
	virtual ~CMaterial();
	
	inline void SetTag( std::string tag )
	{
		
		m_Tag = tag;
		
	}

	void AddFrame( CMaterialFrame * );
	
};

#endif
